package ass.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ass.beans.CinemaBean;
import ass.beans.CinemaMovieBean;
import ass.beans.MovieBean;
import ass.dao.support.CinemaDAOImpl;
import ass.dao.support.CinemaMovieDAOImpl;
import ass.dao.support.MovieDAOImpl;

/**
 * Servlet implementation class MovieDetail2
 */
public class MovieDetail2 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public MovieDetail2() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String id = (String) request.getParameter("id");
		MovieDAOImpl movieImpl = new MovieDAOImpl();
		MovieBean movieBean = movieImpl.getMovie(Integer.parseInt(id));

		CinemaDAOImpl cinemaDAO = new CinemaDAOImpl();
		List<CinemaBean> cinemabeanlist = cinemaDAO.getCinema();

		// CinemaMovieDAOImpl cinemaDAO = new CinemaMovieDAOImpl();
		// List<CinemaMovieBean> cinemalist =
		// cinemaDAO.getCinemaByMovieID(Integer.parseInt(id));
		//

		CinemaMovieDAOImpl timeDAO = new CinemaMovieDAOImpl();
		List<CinemaMovieBean> showtimelist = timeDAO
				.getShowTimeByMovieID(Integer.parseInt(id));

		request.setAttribute("movieBean", movieBean);
		request.setAttribute("cinemabeanlist", cinemabeanlist);
		request.setAttribute("showtimelist", showtimelist);

		String nextJSP = "";

		nextJSP = "/userTicketBooking.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(nextJSP);
		dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
